package com.sqsf.test;


import com.sqsf.dao.AccountDao;
import com.sqsf.javabean.Account;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:spring.xml")
public class MyTest {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    AccountDao accountDao;
    @Autowired
    AccountService accountService;


    @Test
    public void select(){
        String sql="select * from account";
        RowMapper<Account> rm=new BeanPropertyRowMapper<>(Account.class);
        List<Account> query = jdbcTemplate.query(sql, rm);
        for (Account account : query) {
            System.out.println(account);
        }
    }
    @Test
    public void accountService(){
        accountService.transfer("tianqi","zhaoliu",5000);
    }
    @Test
    public void accountDao(){
        // accountDao.updateAddMoneyByName("zhangsan",2);
        accountDao.updateSubMoneyByName("zhangsan",5);
    }
}